function varargout = untitled(varargin)
clc
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

% 选择 
function listbox1_Callback(hObject, eventdata, handles)
global selectContents 

selectContents = cellstr(get(hObject,'String'));
selectNum = get(hObject,'Value');%取出选取位置
selectName = selectContents(selectNum);% 取出字符丄1�7 
%取出选取位置 取反
if(handles.selectNumS(selectNum) > 0.5)
    handles.selectNumS(selectNum) = 0;
else
    handles.selectNumS(selectNum) = 1;
end

cla reset;
cavData = handles.cavData;
legendList = {};
for i = 1:length(cavData.textdata)
    if handles.selectNumS(i) > 0.5
        legendList = [legendList selectContents(i)]
        plot(cavData.data(:,1),cavData.data(:,i),'-o');
        hold on;
    end 
end
legend(legendList); %线条注释,多条的话:legend('xxx','xxx2','xxx3'＄1�7
guidata (hObject, handles);  %更新

%------------------------数据选取 初始数据读取 --------------------------------%
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% -------------------------清除 -------------------------------------------%
function clear_ClickedCallback(hObject, eventdata, handles)
for i = 1:length(handles.selectNumS)
    handles.selectNumS(i) = 0;
end 
guidata (hObject, handles);  %更新
cla reset;

% -------------------------   打开文件    -------------------------------------------
function uipushtool6_ClickedCallback(hObject, eventdata, handles)
global g_csv_mane
global show_pos
global g_min_k
global last_slider_pos
g_min_k = 0.01;
last_slider_pos =0.5
[dname,filepath]= uigetfile('*.csv');
cavdir = [filepath dname];
g_csv_mane =  cavdir
cavData =importdata(g_csv_mane); 
set(handles.CSVtext,'String',g_csv_mane);
% 取出变量名称 
name =''
for i = 1:length(cavData.textdata)
    name = [name cavData.textdata(i)] ;
end 
show_pos= length(cavData.data(:,1))-1
set(handles.listbox1,'String',name);
set(handles.edit2, 'String',num2str(cavData.data(show_pos,2)*0.25,'%f'));
handles.cavData = cavData;
handles.selectNumS = zeros(1,length(cavData.textdata));


guidata (hObject, handles);  %更新

% --- Executes when figure1 is resized.
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% ----------------------- 刷新 ---------------------------------------------
function uitoggletool9_ClickedCallback(hObject, eventdata, handles)
global selectContents 
global g_csv_mane
global show_pos

cla reset;
guidata (hObject, handles);  %更新
name =''
if slider_ctrl == 0
    cavData =importdata(g_csv_mane); 
    handles.cavData = cavData;
    set(handles.CSVtext,'String',g_csv_mane);
    % 取出变量名称 
    name =''
    for i = 1:length(cavData.textdata)
        name = [name cavData.textdata(i)] ;
    end 
    set(handles.listbox1,'String',name);
end
cavData= handles.cavData;


    
cavData = handles.cavData;
legendList = {};
set(handles.edit2, 'String',num2str(cavData.data(show_pos,2)*0.25,'%f'));

for i = 1:length(cavData.textdata)
    if handles.selectNumS(i) > 0.5
        legendList = [legendList selectContents(i)]
        plot(cavData.data(:,1),cavData.data(:,i),'-o');
        hold on;
    end 
end
legend(legendList); %线条注释,多条的话:legend('xxx','xxx2','xxx3'�


guidata (hObject, handles);  %更新

% --- Executes on key press with focus on figure1 or any of its controls.
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)

if isempty(eventdata.Modifier)%判断是否有快捷键
    ctrl='';%无则赋值为空
else
    ctrl=eventdata.Modifier{1};%有，则取出辅助键
end
switch ctrl
    case 'control'%辅助键为Ctrl时
        uitoggletool9_ClickedCallback(hObject, eventdata, handles)
    otherwise
end


uitoggletool9_ClickedCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

